/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            distributionModeManageInfo: {
                distributionModes: [],
                total: 0,
                records: 1,
                moreCondition: false,
                shopId: '',
                conditions: {
                    modeId: '',
                    modeName: '',
                    shopId: '',
                    statusCd: ''
                }
            }
        },
        _initMethod: function () {
            $that._listDistributionModes(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('distributionModeManage', 'listDistributionMode', function (_param) {
                $that._listDistributionModes(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listDistributionModes(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listDistributionModes: function (_page, _rows) {
                $that.distributionModeManageInfo.conditions.page = _page;
                $that.distributionModeManageInfo.conditions.row = _rows;
                $that.distributionModeManageInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                var param = {
                    params: $that.distributionModeManageInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/distributionMode/queryDistributionMode',
                    param,
                    function (json, res) {
                        var _distributionModeManageInfo = JSON.parse(json);
                        $that.distributionModeManageInfo.total = _distributionModeManageInfo.total;
                        $that.distributionModeManageInfo.records = _distributionModeManageInfo.records;
                        $that.distributionModeManageInfo.distributionModes = _distributionModeManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.distributionModeManageInfo.records,
                            dataCount: $that.distributionModeManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddDistributionModeModal: function () {
                vc.emit('addDistributionMode', 'openAddDistributionModeModal', {});
            },
            _openEditDistributionModeModel: function (_distributionMode) {
                vc.emit('editDistributionMode', 'openEditDistributionModeModal', _distributionMode);
            },
            _openDeleteDistributionModeModel: function (_distributionMode) {
                vc.emit('deleteDistributionMode', 'openDeleteDistributionModeModal', _distributionMode);
            },
            _queryDistributionModeMethod: function () {
                $that._listDistributionModes(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.distributionModeManageInfo.moreCondition) {
                    $that.distributionModeManageInfo.moreCondition = false;
                } else {
                    $that.distributionModeManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
